package me.flyray.crm.core.biz;

import java.util.List;

import com.github.wxiaoqi.security.biz.common.crm.request.customerAccountJournalRequest;
import me.flyray.crm.core.entity.FreezeJournal;
import me.flyray.crm.core.mapper.FreezeJournalMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.wxiaoqi.security.common.biz.BaseBiz;
import com.github.wxiaoqi.security.common.msg.TableResultResponse;

import tk.mybatis.mapper.entity.Example;
import tk.mybatis.mapper.entity.Example.Criteria;

/**
 * 冻结流水表
 *
 * @author centerroot
 * @email ${email}
 * @date 2018-07-16 10:15:49
 */
@Service
public class FreezeJournalBiz extends BaseBiz<FreezeJournalMapper, FreezeJournal> {
	
	private static final Logger logger= LoggerFactory.getLogger(FreezeJournalBiz.class);
	
	public TableResultResponse<FreezeJournal> queryFreezeJournals(customerAccountJournalRequest param) {
		logger.info("查询冻结流水表,请求参数。。。{}"+param);
		Example example = new Example(FreezeJournal.class);
		Criteria criteria = null;		
		if (!StringUtils.isEmpty(param.getPlatformId())) {
			if(criteria==null){
        		criteria=example.createCriteria();
        	}
			criteria.andEqualTo("platformId", param.getPlatformId());
		}
		if (!StringUtils.isEmpty(param.getTradeType())) {
			if(criteria==null){
        		criteria=example.createCriteria();
        	}
			criteria.andEqualTo("tradeType", param.getTradeType());
		}
		if (!StringUtils.isEmpty(param.getOrderNo())) {
			if(criteria==null){
        		criteria=example.createCriteria();
        	}
			criteria.andEqualTo("orderNo", param.getOrderNo());
		}
		if(criteria==null){
    		criteria=example.createCriteria();
    	}
		criteria.andEqualTo("tccFlag", "1");//生效数据
		example.setOrderByClause("create_time DESC");
		Page<FreezeJournal> result = PageHelper.startPage(param.getPage(), param.getLimit());
		List<FreezeJournal> list = mapper.selectByExample(example);
		TableResultResponse<FreezeJournal> table = new TableResultResponse<>(result.getTotal(), list);
		return table;
	}
}